<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page trimDirectiveWhitespaces="true" %>
<fmt:setLocale value="zh_CN"/>
<div class="cg_container">
	<!-- t改为shieldTarget，且为jQuery选择器形式,notAutoSubmit表示不自动提交 -->
    <form id="cgSearchForm" action="${ctxPathA}/system/codegen/tables" method="post" shieldTarget="#cg_tablesDiv" class="searchForm" notAutoSubmit>
        <div class="searchForm">
            <b>连接：</b>
			<!-- 增加样式select2_plugin，data-v表示默认值-->    
            <select name="conn" class="select2_plugin">
            	<option value="0">本项目库</option>
    <c:forEach var="dbset" items="${dbsets }">
    			<option value="${dbset.id }">${dbset.dbSetName }</option>
    </c:forEach>
            </select>
            <b>表名：</b><input type="text" name="tableName" id="codeGenTableName" style="width: 100px;">
            <input class="button submit" type="submit" name="doSearch" value="查询">
        </div>
	    <div class="midtab">
			<a data-target="cg_tables" class="cg_tables current cur " href="javascript:void(0)" >第一步：搜索表</a><img src="${ctxPath }/images/icon/import.png" class="inited">&nbsp;&nbsp;&nbsp;
			<a data-target="cg_modelSet" v="0" class="cg_modelSet" href="javascript:void(0)" >第二步：配置model字段</a><img src="${ctxPath }/images/icon/import.png" class="inited">&nbsp;&nbsp;
			<a data-target="cg_modelSet" v="1,2" class="cg_paramsSet" href="javascript:void(0)" >第三步：配置输出参数</a><img src="${ctxPath }/images/icon/import.png" class="inited">&nbsp;&nbsp;
			<a data-target="cg_preview" v="0" class="cg_preview" href="javascript:void(0)" >第四步：代码预览</a><img src="${ctxPath }/images/icon/import.png" class="inited">&nbsp;&nbsp;
			<a data-target="cg_preview" v="1" href="javascript:void(0)" >第五步：输出</a>
		</div>
    </form>
    <div id="cg_tablesDiv" class="midtabDiv "><div style="font-size: 14px; width:800px;margin-top: 50px;text-align: center;" class="tips">请先搜索表</div></div>
    <div id="cg_modelSetDiv" class="midtabDiv no-shu" style="display: none;"><div style="font-size: 14px; width:800px;margin-top: 50px;text-align: center;" class="tips">未在上一步中选择表</div></div>
    <div id="cg_previewDiv" class="midtabDiv no-shu" style="display: none;"><div style="font-size: 14px; width:800px;margin-top: 50px;text-align: center;" class="tips">没有预览结果，请检查前面的步骤是否已经完成</div></div>
</div>
<script>
/* 搜索 */
$("#codeGenTableName").keyup(function(){
	var tableE = $("#cg_tablesDiv").find("table");
	if (tableE.length > 0) {
	  	var _defaults = {
			/**前景色*/
			foreground: 'red',    
			/**背景色*/
		    background: 'yellow'    
		};
		var $search = $(this);
	    var searchKey = $.trim($search.val());
	    if (searchKey) {
	    	var options = $.extend(true, _defaults, getSettings($search));
	    	tableE.find("tr.datatr").hide();
	    	tableE.find("tr.datatr").filter(function() {
	    		if ($(this).text().toLowerCase().indexOf(searchKey.toLowerCase())!=-1) {
	    			ShieldJS.debug(searchKey);
	    			var reg = new RegExp("("+searchKey+")", "gi"); //全局并忽略大小写
	    			$(this).find("td.datatd").each(function(i) {
	    				var newstr = $(this).data("html").replace(reg, '<strong style="background-color: '+options.background+';color: '+options.foreground+';">$1</strong>');
	    				$(this).html(newstr);
	                });
	    			return true;
	    		}
	    		return false; 
	    	}).show();
	    } else {
	    	tableE.find("tr.datatr").show().find("td.datatd").each(function(i) {
				$(this).html($(this).data("html"));
			});
		}
    }
});
$(".midtab").find("a").click(function(){
	var thisid = $(this).data("target");
	var parE = $(this).closest(".cg_container");
	var v = $(this).attr("v");
	$(".midtab").find("a").removeClass("current cur");
	$(this).addClass("current cur");
	parE.find(".midtabDiv").hide();
	parE.find("#"+thisid+"Div").show();
	if (v) {
		var partshowEs = parE.find("#"+thisid+"Div").find(".partshow");
		partshowEs.hide();
		if (v.indexOf(",") != -1) { //多个
	        var vs = v.split(",");
			$.each(vs, function(i, n) {
		        partshowEs.eq(n).show();
            })
        } else {
			partshowEs.eq(v).show();
        }
    }
	
});
//默认显示
$(".bnt1").click(function () {
	$(".cg_tables").click();
});
//配置
var cg_modelsetshowclickCallback = function () { //disabledBtn方法将button置为不可用影响了click方法的执行
	$(".cg_modelSet").click();
};
//预览
var cg_previewBtnclickCallback = function () { 
	$(".cg_preview").click();
};
</script>
<!-- 代码预览 -->
<link rel="stylesheet" href="//cdn.staticfile.org/highlight.js/10.0.3/styles/an-old-hope.min.css">
<script src="//cdn.staticfile.org/highlight.js/10.0.3/highlight.min.js"></script>